/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 *
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 *
 * Company website: http://www.x2engine.com
 * Community and support website: http://www.x2community.com
 *
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license
 * to install and use this Software for your internal business purposes.
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong
 * exclusively to X2Engine.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

// called when a tab is clicked
function tabSelected(event, ui) {
	// set field SelectedTab for use in POST request
	$('#SelectedTab').val(ui.newTab.attr('aria-controls'));

	if(ui.newTab.attr('aria-controls') == 'new-event') {
		// switch labels Due Date vs Start Date
		$('#due-date-label').css('display', 'none');
		$('#start-date-label').css('display', 'block');

		// show end date
		$('#end-date-label').css('display', 'block');
		$('#end-date-input').css('display', 'inline-block');

		// show action-event-panel
		$('#action-event-panel').css('display', 'block');

	} else if(ui.newTab.attr('aria-controls') == 'new-action') {
		$('#due-date-label').css('display', 'block');
		$('#start-date-label').css('display', 'none');

		// hide end date
		$('#end-date-label').css('display', 'none');
		$('#end-date-input').css('display', 'none');

		// show action-event-panel
		$('#action-event-panel').css('display', 'block');
	} else if(ui.newTab.attr('aria-controls') == 'log-a-call') {
		// hide action-event-panel
		$('#action-event-panel').css('display', 'none');
	} else if(ui.newTab.attr('aria-controls') == 'new-comment') {
		// hide action-event-panel
		$('#action-event-panel').css('display', 'none');
	}
}

// Sanity check the form before we submit
// if sanity check fails, tell the user what's insane, and cancel submit (by returning false)
function sanityCheck() {

}

function publisherUpdates() {
	if($('#calendar').length !== 0) // if we are in calendar module
		$('#calendar').fullCalendar('refetchEvents'); // refresh calendar

	if($('.list-view').length !== 0)
		$.fn.yiiListView.update($('.list-view').attr('id'));
}


function resetPublisher() {

	// reset group checkbox (if checked)
	if($('#groupCheckbox').is(':checked')) {
		$('#groupCheckbox').click(); // unchecks group checkbox, and calls ajax function to restor Assigned To to list of users
	}

	// reset textarea and dropdowns
	$('#publisher-form select, #publisher-form input[type=text], #publisher-form textarea').each(function(i) {
		$(this).val($(this).data('defaultValue'));
	});

	// reset checkboxes
	$('#publisher-form input[type=checkbox]').each(function(i) {
		$(this).attr('checked', $(this).data('defaultValue'));
	});

	// reset save button
	$('#save-publisher').removeClass('highlight');
}
